import 'package:bxultimate/data/request/user_request.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import 'state.dart';

class FeedBackController extends GetxController {
  final FeedBackState state = FeedBackState();

  TextEditingController feedbackController = TextEditingController();
  TextEditingController contactController = TextEditingController();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  void save() async {
    if(feedbackController.text == ''){
      SmartDialog.showNotify(msg: '请输入反馈内容', notifyType: NotifyType.failure);
      return;
    }
    var data = {
      "feedback": feedbackController.text,
    };
    if(contactController.text != ''){
      data["contact"] = contactController.text;
    }
    if (state.imgList.length > 0) {
      data["picture"] = state.imgList[0].path;
    }
    await UserRequest.userFeedback(data);
    SmartDialog.showNotify(msg: '提交成功', notifyType: NotifyType.success);
    Get.back();
  }
}
